<template>
  <div class="record-account">
    <div class="opers flex v-c">
      <el-form :inline="true" class="filter-blk flex-1">
        <el-form-item label="通讯类型">
          <el-select v-model="filterForm.type" placeholder="请选择">
            <el-option
              :label="item.name"
              :value="item.id"
              v-for="(item, key) in typeList"
              :key="key"
            ></el-option>
          </el-select>
        </el-form-item>
        <el-form-item class="ml-20" label="设备号">
          <el-input
            placeholder="请输入设备号"
            v-model.trim="filterForm.number"
          ></el-input>
        </el-form-item>
        <el-form-item class="ml-20" label="单位名称">
          <el-input
            placeholder="请输入单位名称"
            v-model.trim="filterForm.businessName"
          ></el-input>
        </el-form-item>
        <el-form-item>
          <el-button type="primary" @click="searchAction">
            <i class="iconfont icon-search"></i> 搜索
          </el-button>
          <el-button type="primary" @click="resetAction">
            <i class="iconfont icon-refresh"></i> 重置
          </el-button>
          <!-- <el-button type="green" @click="refreshAction">
                        <i class="iconfont"></i> 更新状态
                    </el-button> -->
        </el-form-item>
      </el-form>
    </div>
    <el-table
      class="mt-20"
      :data="dataList"
      style="width: 100%"
      v-loading="loading"
    >
      <el-table-column prop="number" label="设备号"></el-table-column>
      <el-table-column prop="businessName" label="单位名称"></el-table-column>
      <el-table-column prop="contacts" label="联系人姓名"></el-table-column>
      <el-table-column prop="phone" label="电话"></el-table-column>
      <el-table-column prop="type" label="通讯方式">
        <template slot-scope="scope">
          {{ typeList[scope.row.type].name }}
        </template>
      </el-table-column>
      <el-table-column prop="status" label="状态">
        <template slot-scope="scope">
          <!-- <span
                        :class="{
                            'color-green': scope.row.state == 2,
                            'color-red': scope.row.state == 3,
                        }"
                    > -->
          <span>
            {{
              typeList[scope.row.type].name == "语音"
                ? stateMap[scope.row.state]
                : stateMassage[scope.row.state]
            }}
          </span>
        </template>
      </el-table-column>
      <el-table-column prop="time" label="时间"></el-table-column>
    </el-table>
    <el-pagination
      v-if="total > 0"
      class="text-right mt-20 mr-20"
      @current-change="handleCurrentChange"
      :current-page="currentPage"
      :page-size="pageSize"
      layout="prev, pager, next, total, jumper"
      :total="total"
    >
    </el-pagination>
  </div>
</template>
<script>
import { mapState } from "vuex";
export default {
  name: "RecordAccount",
  props: {
    activeData: {
      type: Object,
      default() {
        return null;
      },
    },
  },
  computed: {
    ...mapState(["scale", "siteInfos"]),
  },
  data() {
    return {
      filterForm: {
        number: "",
        type: "",
        businessName: "",
      },
      stateMap: {
        // 1: "发送中",
        // 2: "发送成功",
        // 3: "发送失败",
        1: "未接通",
        2: "已接通",
        3: "未接通",
      },
      stateMassage: {
        1: "未送达",
        2: "已发送",
        3: "未送达",
      },
      total: 0,
      currentPage: 1,
      pageSize: 10,
      loading: false,
      dataList: [],
      newModalVisible: false,
      adding: false,
      deleting: false,
      typeList: [
        {
          id: "",
          name: "全部",
        },
        {
          id: 1,
          name: "短信",
        },
        {
          id: 2,
          name: "语音",
        },
      ],
    };
  },
  methods: {
    refreshAction() {
      const params = {};
      if (this.siteInfos.userType == 2) {
        params.businessId = this.siteInfos.homeId;
      } else {
        params.businessId = this.activeData.id;
      }
      this.$post("/notice/notice/updateStateYZX", params)
        .then((res) => {
          this.getData(this.currentPage);
        })
        .catch((err) => {
          this.$message.error(err.msg);
        });
    },
    getData(page) {
      this.loading = true;
      let params = Object.assign(
        {
          page: page,
          limit: this.pageSize,
          businessId: this.activeData.id,
        },
        this.filterForm
      );
      this.$get(
        "/fireFightingIOT/itemSetup/getCommunicationRecordListPage",
        params
      ).then(
        (res) => {
          this.loading = false;
          let data = res.data;
          this.currentPage = page;
          this.total = data.totalSize;
          this.dataList = data.Items;
        },
        (err) => {
          this.loading = false;
          this.$message.error(err.msg);
        }
      );
    },
    handleCurrentChange(page) {
      this.getData(page);
    },
    searchAction() {
      this.getData(1);
    },
    resetAction() {
      this.filterForm = {};
    },
  },
  created() {
    this.getData(1);
  },
};
</script>
